package com.caption.jdk.function;

import com.caption.jdk.lambda.Person;

public class TestFunction {

    public static void main(String[] args) {
        Person p = new Person("张三", 20);
        PrintDetail<Person, String> printDetail = new PrintDetail(p);
        /**
         * print定义的是consumer接口
         */
        printDetail.print(o -> System.out.println(o.getName()));

        printDetail.print2(o -> System.out.println(o.getName()),o->System.out.println("执行完成之后"));

        /**
         * get是supplier接口 ,如果p1为空则返回新的person对象
         */
        Person p2 = printDetail.get(() -> new Person("李四", 20));
        System.out.println(p2);
        /**
         * getName是function接口
         */
        String name = printDetail.getName(o -> o.getName());
        System.out.println(name);

        /**
         * getAge方法是两个function接口，在f1完成之后在把得到的结果交个f2运行
         */
        Integer age = printDetail.getAge(o -> o.getAge(), o2 -> o2 * 10);
        System.out.println(age);

        /**
         *just 是一个predicate接口
         */
        boolean bool = printDetail.just(o -> o.getName().length() > 3);
        System.out.println(bool);
        /**
         * 两个predicate条件同时满足才会返回
         */
        boolean bool2 = printDetail.just2(o -> o.getName().length() > 1, o -> o.getAge() > 15);
        System.out.println(bool2);
    }
}
